package com.mcf.xiaolinju.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.mcf.xiaolinju.entity.Tagmessage;
import com.mcf.xiaolinju.mapper.DynamicMapper;
import com.mcf.xiaolinju.mapper.TagmessageMapper;
import com.mcf.xiaolinju.service.ITagmessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mcf
 * @since 2022-02-22
 */
@Service
public class TagmessageServiceImpl extends ServiceImpl<TagmessageMapper, Tagmessage> implements ITagmessageService {
@Resource
TagmessageMapper tagmessageMapper;

@Resource
    DynamicMapper dynamicMapper;
    public void updateTagmessage(int id, int userid) {
        Tagmessage one = this.getOne(Wrappers.<Tagmessage>lambdaQuery().eq(Tagmessage::getDynamicid,id)
                .eq(Tagmessage::getTagsid,userid));
        if(one!=null){
            tagmessageMapper.deleteone(id,userid);
            dynamicMapper.subpraisecount(id);
        }
        else{
            Date date=new Date();
            LocalDateTime ldt=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
           tagmessageMapper.insertone(id,userid,ldt);
           dynamicMapper.addpraisecount(id);
        }


    }
}
